package com.shf.mapper;

import com.shf.entity.Role;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 权限管理
 * @author 叶枫
 */
public interface RoleMapper {
    @Select("select r.* from role r,user_role ur where r.id = ur.roleId and ur.userId=#{userId}")
    List<Role> findRolesByUserid(int userId);

    /**
     * 查询所有角色
     * @return
     */
    @Select("select * from role")
    List<Role> findAllRole();

    /**
     * 添加角色关联
     * @param userId
     * @param roleId
     */
    @Insert("insert into user_role values (#{userId},#{roleId})")
    void addRoleToUser(@Param("userId") String userId,@Param("roleId") String roleId);

    /**
     * 删除用户权限
     * @param id
     */
    @Delete("delete from user_role where userId = #{id}")
    void deleteRoleUser(String id);

    /**
     * 添加权限
     * @param role
     */
    @Insert("insert into role values (#{id},#{roleName},#{roleDesc})")
    void saveRole(Role role);

    /**
     * 根据id查询角色
     * @param id
     * @return
     */
    @Select("select * from role where id = #{id}")
    Role findRoleById(String id);
@Insert("insert into role_permission values (#{permissionId},#{roleId})")
    void addPermissionToRole(@Param("permissionId") String roleId,@Param("roleId") String[] ids);


    Role roleDetailById(String id);

    /**
     * 删除角色
     * @param id
     */
    @Delete("delete from role where id = #{id}")
    void deleteRole(String id);

    /**
     * 多选删除角色
     * @param ids
     */
    void deleteManyRole( @Param("ids") String[] ids);
}
